angular.module("NTApp").controller('ScanDeviceIdCtrl', function($state, WXService) {
  var s = this;
  WXService.setListToScan(false);
  WXService.getCookieData('hvacUserInfo');
  WXService.getOnlineToken()
    .then(function(result) {
      result.status = true;
      return result;
    })
    .then(function(data) {
      data && data.status ? WXConfig(data) : alert('请退出重试');
    })

  function WXConfig(configInfo) {
    wx.config({
      beta: true,
      debug: false,
      appId: configInfo.appId,
      timestamp: configInfo.timestamp,
      nonceStr: configInfo.nonce,
      signature: configInfo.signature,
      appSecret: configInfo.appSecret,
      jsApiList: [
        'onMenuShareAppMessage',
        'scanQRCode',
        'configWXDeviceWiFi',
        'onMenuShareTimeline',
        'getLocation',
        'hideMenuItems',
        'showMenuItems',
        'hideAllNonBaseMenuItem'
      ]
    });

    wx.ready(function() {
      wx.scanQRCode({
        needResult: 1,
        scanType: ["qrCode", "barCode"],
        success: function(res) {
          $state.go('DeviceBinding', {
            idStr: res.resultStr
          });
        },
        fail: function() {
          alert('something error');
        }
      });
    });
    wx.error(function(res) {

    });
  }

  s.back = function() {
    wx.closeWindow('cancel');
  }
});
